package com.haoting.common.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("created",new Date(),metaObject);//传的是类的属性名称
        this.setFieldValByName("modified",new Date(),metaObject);
        this.setFieldValByName("commentCount",0,metaObject);
        this.setFieldValByName("supportCount",0,metaObject);
        this.setFieldValByName("collectionCount",0,metaObject);
        this.setFieldValByName("matchStatus",0,metaObject);
        this.setFieldValByName("type",0,metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("modified",new Date(),metaObject);
    }
}
